<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <!-- <el-form-item label="修改物料id" prop="partUuid">
        <el-input
          v-model="queryParams.partUuid"
          placeholder="请输入修改物料id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="类型" prop="type">
        <el-input
          v-model="queryParams.type"
          placeholder="请输入类型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="类型" prop="type">
        <el-select v-model="queryParams.type" placeholder="类型" clearable>
          <el-option
            v-for="dict in dict.type.mtr_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="物料" prop="partId">
        <el-input
          v-model="queryParams.partId"
          placeholder="请输入物料"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="名称" prop="chinaName">
        <el-input
          v-model="queryParams.chinaName"
          placeholder="请输入名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="修改人id" prop="updateUserId">
        <el-input
          v-model="queryParams.updateUserId"
          placeholder="请输入修改人id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="昵称" prop="updateNickname">
        <el-input
          v-model="queryParams.updateNickname"
          placeholder="请输入昵称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="修改人" prop="updateName">
        <el-input
          v-model="queryParams.updateName"
          placeholder="请输入修改人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="参数" prop="param">
        <el-input
          v-model="queryParams.param"
          placeholder="请输入参数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="年" prop="year">
        <el-input
          v-model="queryParams.year"
          placeholder="请输入年"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="月" prop="moth">
        <el-input
          v-model="queryParams.moth"
          placeholder="请输入月"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料时间" prop="priceTime">
        <el-date-picker clearable
          v-model="queryParams.priceTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择物料时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="登录ip" prop="ipaddr">
        <el-input
          v-model="queryParams.ipaddr"
          placeholder="请输入登录ip"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="登录地点" prop="loginlocation">
        <el-input
          v-model="queryParams.loginlocation"
          placeholder="请输入登录地点"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="浏览器" prop="browser">
        <el-input
          v-model="queryParams.browser"
          placeholder="请输入浏览器"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="登录时间" prop="logintime">
        <el-date-picker clearable
          v-model="queryParams.logintime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择登录时间">
        </el-date-picker>
      </el-form-item> -->
      <el-form-item label="登录时间">
        <el-date-picker
          v-model="queryParams.logintime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <!-- <el-form-item label="备注" prop="marks">
        <el-input
          v-model="queryParams.marks"
          placeholder="请输入备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:upRecord:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:upRecord:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:upRecord:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:upRecord:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="upRecordList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="修改物料id" align="center" prop="partUuid" /> -->
      <el-table-column label="类型" align="center" prop="type" >
        <template slot-scope="scope" >
          <dict-tag :options="dict.type.mtr_type" :value="scope.row.type" />
        </template>
      </el-table-column>
      <el-table-column label="物料" align="center" prop="partId" min-width="150px" />
      <el-table-column label="名称" align="center" prop="chinaName" min-width="150px" />
      <!-- <el-table-column label="修改人id" align="center" prop="updateUserId" /> -->
      <el-table-column label="昵称" align="center" prop="updateNickname" />
      <el-table-column label="修改人" align="center" prop="updateName" />
      <!-- <el-table-column label="参数" align="center" prop="param" /> -->
      <!-- <el-table-column label="年" align="center" prop="year" />
      <el-table-column label="月" align="center" prop="moth" />
      <el-table-column label="物料时间" align="center" prop="priceTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.priceTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="登录ip" align="center" prop="ipaddr" />
      <el-table-column label="登录地点" align="center" prop="loginlocation" />
      <el-table-column label="浏览器" align="center" prop="browser" />
      <el-table-column label="登录时间" align="center" prop="logintime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.logintime, '{y}-{m}-{d} {h}:{m}:{s}') }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="备注" align="center" prop="marks" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" min-width="90px" >
        <template slot-scope="scope">
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:upRecord:edit']"
          >修改</el-button> -->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-query"
            @click="handleInfo(scope.row)"
            v-hasPermi="['system:upRecord:query']"
          >详情</el-button>
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:upRecord:remove']"
          >删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改修改记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <!-- <el-form-item label="修改物料id" prop="partUuid">
          <el-input v-model="form.partUuid" placeholder="请输入修改物料id" />
        </el-form-item> -->
        <el-form-item label="物料" prop="partId">
          <el-input v-model="form.partId" placeholder="请输入物料" readonly="readonly" />
        </el-form-item>
        <el-form-item label="名称" prop="chinaName">
          <el-input v-model="form.chinaName" placeholder="请输入名称" readonly="readonly" />
        </el-form-item>
        <el-form-item label="修改人id" prop="updateUserId">
          <el-input v-model="form.updateUserId" placeholder="请输入修改人id" readonly="readonly" />
        </el-form-item>
        <el-form-item label="昵称" prop="updateNickname">
          <el-input v-model="form.updateNickname" placeholder="请输入昵称" readonly="readonly" />
        </el-form-item>
        <el-form-item label="修改人" prop="updateName">
          <el-input v-model="form.updateName" placeholder="请输入修改人" readonly="readonly"/>
        </el-form-item>
        <el-form-item label="参数" prop="param">
          <el-input v-model="form.param" placeholder="请输入参数" readonly="readonly" />
        </el-form-item>
        <!-- <el-form-item label="年" prop="year">
          <el-input v-model="form.year" placeholder="请输入年" />
        </el-form-item>
        <el-form-item label="月" prop="moth">
          <el-input v-model="form.moth" placeholder="请输入月" />
        </el-form-item>
        <el-form-item label="物料时间" prop="priceTime">
          <el-date-picker clearable
            v-model="form.priceTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择物料时间">
          </el-date-picker>
        </el-form-item> -->
        <el-form-item label="登录ip" prop="ipaddr">
          <el-input v-model="form.ipaddr" placeholder="请输入登录ip" readonly="readonly"  />
        </el-form-item>
        <el-form-item label="登录地点" prop="loginlocation">
          <el-input v-model="form.loginlocation" placeholder="请输入登录地点" readonly="readonly" />
        </el-form-item>
        <el-form-item label="浏览器" prop="browser" >
          <el-input v-model="form.browser" placeholder="请输入浏览器" readonly="readonly" />
        </el-form-item>
        <!-- <el-form-item label="登录时间" prop="logintime" >
          <el-date-picker clearable
            v-model="form.logintime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择登录时间"
            readonly="readonly" >
          </el-date-picker>
        </el-form-item> -->
        <!-- <el-form-item label="备注" prop="marks">
          <el-input v-model="form.marks" placeholder="请输入备注" />
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <!-- <el-button type="primary" @click="submitForm">确 定</el-button> -->
        <el-button @click="cancel">确 定</el-button>
      </div>
    </el-dialog>
    
  </div>
</template>

<script>
import { listUpRecord, getUpRecord, delUpRecord, addUpRecord, updateUpRecord } from "@/api/factory/bom/upRecord";

export default {
  name: "UpRecord",
  dicts: ['mtr_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 修改记录表格数据
      upRecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        partUuid: null,
        type: null,
        partId: null,
        chinaName: null,
        updateUserId: null,
        updateNickname: null,
        updateName: null,
        param: null,
        year: null,
        moth: null,
        priceTime: null,
        ipaddr: null,
        loginlocation: null,
        browser: null,
        logintime: null,
        marks: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询修改记录列表 */
    getList() {
      this.loading = true;
      listUpRecord(this.queryParams).then(response => {
        this.upRecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        partUuid: null,
        type: null,
        partId: null,
        chinaName: null,
        updateUserId: null,
        updateNickname: null,
        updateName: null,
        param: null,
        year: null,
        moth: null,
        priceTime: null,
        ipaddr: null,
        loginlocation: null,
        browser: null,
        logintime: null,
        createTime: null,
        updateTime: null,
        marks: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加修改记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getUpRecord(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改修改记录";
      });
    },
    handleInfo(row) {
      this.reset();
      const id = row.id || this.ids
      getUpRecord(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改详情记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateUpRecord(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addUpRecord(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除修改记录编号为"' + ids + '"的数据项？').then(function() {
        return delUpRecord(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/upRecord/export', {
        ...this.queryParams
      }, `record_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
